package com.by.service.impl;

import com.by.bean.Customer;
import com.by.common.bean.PageBean;
import com.by.common.crud.BaseServiceImpl;
import com.by.common.utils.Assert;
import com.by.mapper.CustomerMapper;
import com.by.mapper.UserMapper;
import com.by.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl extends BaseServiceImpl<Customer, CustomerMapper> implements CustomerService {

    @Autowired
    UserMapper userMapper;

    @Override
    public int save(Customer entity) {
        entity.getUser().setType(4);
        int rs = userMapper.save(entity.getUser());
        Assert.isNotSuccess(rs, "用户保存失败");
        entity.setUserId(userMapper.queryId(entity.getUser().getAccount()));
        return super.save(entity);
    }


    /**
     * 根据客户ID查询客户信息
     * @param id
     * @return
     */
    @Override
    public Customer get(Serializable id) {
        return super.get(id);
    }


}
